package com.atguigu.crowd.mvc.config;

import com.atguigu.entity.Admin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.List;

/**
 * 考虑到User对象中仅仅包含账号密码，为了能够获取到原始的Admin对象，专门创建这个类对User类进行扩展
 */
public class SecurityAdmin extends User {

    private Admin  rawAdmin;

    public SecurityAdmin(Admin rawAdmin, List<GrantedAuthority> authorities){

        super(rawAdmin.getLoginAcct(),rawAdmin.getUserPswd(),authorities);
        this.rawAdmin = rawAdmin;

        //密码擦除
        this.rawAdmin.setUserPswd(null);
    }

    public Admin getRawAdmin() {
        return rawAdmin;
    }
}
